namespace WLFramework.Web.Binder
{
    using System.Collections.Generic;
    using System.Linq;

    public sealed class ModelExceptionCollection : List<ModelException>
    {
        public ModelExceptionCollection()
        {
        }

        public ModelException this[string key]
        {
            get 
            {
                return this.Where(k => k.MemberName == key).FirstOrDefault();
            }
            set
            {
                var ex = this.Where(k => k.MemberName == key).FirstOrDefault();
                if (ex != null)
                {
                    this.Remove(ex);
                }

                this.Add(value);
            }
        }
    }
}
